project( socialwhale )

# just for sure, it seems like prior versions don't find Qt4
cmake_minimum_required( VERSION 2.6.0 )

# cmake forces us to set this on linux
if ( COMMAND cmake_policy )
  cmake_policy( SET CMP0003 NEW )
endif( COMMAND cmake_policy )

# header files used in plugins library (whalebase)
set( whalebase_HEADERS
    gui/whaletabbase.h
    gui/WhaleTabBase
    gui/whalebutton.h
    gui/WhaleButton
    gui/interfaces.h
    gui/WhalePlugin
    gui/whaleavatar.h
    gui/WhaleAvatar
    gui/whalestreamtab.h
    gui/WhaleStreamTab
    gui/WhaleAbstractEntry
    gui/whaleabstractentry.h
    gui/WhaleTweetEntry
    gui/whaletweetentry.h
    gui/whaletwitterstreamtab.h
    gui/WhaleTwitterStreamTab
    gui/whalefollowerentry.h
    gui/WhaleFollowerEntry
    gui/whalepluginstarter.h
    gui/WhalePluginStarter
    logic/WhaleAbstractConnect
    logic/whaleabstractconnect.h
    logic/WhaleTwitterConnect
    logic/whaletwitterconnect.h
    logic/cookiejar.h
    logic/thememanager.h
)

# cpp files used in plugins library
set( whalebase_CPPS
    gui/whaletabbase.cpp
    gui/whalebutton.cpp
    gui/whaleavatar.cpp
    gui/whaleabstractentry.cpp
    gui/whaletweetentry.cpp
    gui/whalefollowerentry.cpp
    gui/whalestreamtab.cpp
    gui/whaletwitterstreamtab.cpp
    gui/whalepluginstarter.cpp
    logic/whaleabstractconnect.cpp
    logic/whaletwitterconnect.cpp
    logic/cookiejar.cpp
    logic/thememanager.cpp
)

# combine them into one source
set( whalebase_SRCS
    ${whalebase_CPPS}
    ${whalebase_HEADERS}
)

INSTALL( FILES ${whalebase_HEADERS} DESTINATION include/socialwhale )

# set sources and headers for main application
set( socialwhale_SRCS
    main.cpp
    socialwhale.cpp
    gui/labelbutton.cpp
    gui/homewindow.cpp
    gui/startwindow.cpp
    gui/loginwindow.cpp
    gui/loginbrowser.cpp
    gui/whaletabbase.cpp
    gui/tabscreen.cpp
    gui/whalebutton.cpp
    gui/toolbar.cpp
    gui/toolbar.h
    gui/whalewindow.cpp
    gui/configurationdialog.cpp
    logic/cookiejar.cpp
    logic/user.cpp
    logic/pluginhandler.cpp
    logic/cookiejar.h
    logic/tabmanager.cpp
    logic/whaleplugin.cpp

    ${whalebase_CPPS}
)

# headers used by MOC should be set here 
# (e.g. if the class is child of QObject)
set( socialwhale_MOC_SRCS
    socialwhale.h
    gui/labelbutton.h
    gui/homewindow.h
    gui/startwindow.h
    gui/loginwindow.h
    gui/tabscreen.h
    gui/loginbrowser.h
    gui/whaletabbase.h
    gui/whalebutton.h
    gui/whalewindow.h
    gui/interfaces.h
    gui/configurationdialog.h
    logic/pluginhandler.h
    logic/user.h
    logic/tabmanager.h
    logic/whaleplugin.h

    ${whalebase_HEADERS}
)

# user interface files
set( socialwhale_UI_SRCS
    gui/configurationdialog.ui
)


# and the RCC files
set( socialwhale_RCC_SRCS
    socialwhale.qrc 
)

# end of file listing, start processing

# include qt library
find_package( Qt4 REQUIRED )
include( ${QT_USE_FILE} )
link_directories( ./build )

# let qt handle the sources
qt4_wrap_ui( socialwhale_UIS ${socialwhale_UI_SRCS} )
qt4_wrap_cpp( socialwhale_MOCS ${socialwhale_MOC_SRCS} )
qt4_add_resources( socialwhale_RCCS ${socialwhale_RCC_SRCS} )

# create the executable with the qt generated sources
add_executable( socialwhale
    ${socialwhale_UIS}
    ${socialwhale_SRCS}
    ${socialwhale_MOCS}
    ${socialwhale_RCCS}
)

# create the plugins library
add_library( whalebase ${whalebase_SRCS} )

# cmake doesn't seem to include these automatically (needed for WebKit)
include_directories( 
    ${QT_QTNETWORK_INCLUDE_DIR} 
    ${QT_QTWEBKIT_INCLUDE_DIR} 
    ${CMAKE_INSTALL_PREFIX}/include/socialwhale
    ${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries( socialwhale 
    ${QT_LIBRARIES} 
    ${QT_QTNETWORK_LIBRARY} # like include dirs, we need to set these
    ${QT_QTWEBKIT_LIBRARY} 
    whalebase
    qjson                   # and the qjson library (not included in Qt)
) 

# make install: library and executable
INSTALL( TARGETS socialwhale whalebase
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib/socialwhale
    ARCHIVE DESTINATION lib/socialwhale # maybe not needed
)

IF(WIN32)
    install( DIRECTORY themes DESTINATION ${HOME_DIRECTORY}/SocialWhale )
ELSE()
    install( DIRECTORY themes DESTINATION ${HOME_DIRECTORY}/.socialwhale )
ENDIF()
